
#include <sstream>

#include "plugin_test.h"

//#include "Renderer.h"
//#include "Pluginterface.h"

class ITextureLoader
{
	
public:
	virtual String getLoadableExtensions() = 0;
	virtual void   loadTexture(String sFilename) = 0;
	
};

class TextureMgr
{
	//Maps filename extensions to texture loaders
	std::map<String, ITextureLoader*> m_pTextureLoaderMap;
	//List of texture loaders
	std::vector<ITextureLoader*>      m_pTextureLoaders;
	//Allow texture-loaders to be plugins
	Pluginterface<ITextureLoader>	   m_TextureLoaderPluginterface;
	
public:
	
	TextureMgr()
	{
		
		//for each correct plugin found
			ITextureLoader* pTL = m_TextureLoaderPluginterface.loadAndInstantiatePlugin("pngTextureLoader");
			m_pTextureLoaders.push_back(pTL);
		
			//Now we use a cheap way to tokenise (split) the string around whitespace in order to extract each extension and add it to the map.
			//NOTE: This will replace any already-mapped extensions with the latest one loaded.
			String sExtensions = pTL->getLoadableExtensions();
			std::stringstream ssExtensions(sExtensions);
			String sExtension;
			while (ssExtensions >> sExtension)
				m_pTextureLoaderMap[sExtension] = pTL;
		
	}

};

class OpenGLRenderer : public IRenderer
{
	TextureMgr m_TextureMgr;
public:
	virtual bool init()        { std::cout << "OpenGLRenderer::init()" << std::endl; /*m_TextureMgr.getTexture("car.png");*/ }
	virtual bool drawSprite()  { std::cout << "OpenGLRenderer::drawSprite()" << std::endl; }
	virtual bool renderScene() { std::cout << "OpenGLRenderer::renderScene()" << std::endl; }
	
	//static void testFunc();
	
};

//extern "C" PLUGIN_API void OpenGLRenderer::testFunc() { std::cout << "testFunc" << std::endl; }

DEFINE_PLUGIN( OpenGLRenderer, IRenderer )

